package com.cloud.servicezuul.service.impl;

import com.cloud.servicezuul.dao.GreySettingMapper;
import com.cloud.servicezuul.dao.OnlineSettingMapper;
import com.cloud.servicezuul.entity.GreySetting;
import com.cloud.servicezuul.entity.OnlineSetting;
import com.cloud.servicezuul.service.GreyReleaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GreyReleaseServiceImpl implements GreyReleaseService {

    @Autowired
    GreySettingMapper greySettingMapper;

    @Autowired
    OnlineSettingMapper onlineSettingMapper;

    @Override
    public List<GreySetting> queryGerySetting(String userId) {
        GreySetting setting = GreySetting.QueryBuild().userId(Integer.parseInt(userId))
                .inUse(1).build();
        return greySettingMapper.queryGreySetting(setting);
    }

    @Override
    public GreySetting queryGreySettingByUserIdAndServiceName(String userId, String serviceName) {
        GreySetting setting = GreySetting.QueryBuild().userId(Integer.parseInt(userId)).serviceName(serviceName).inUse(1).build();
        return greySettingMapper.queryGreySettingLimit1(setting);
    }

    @Override
    public OnlineSetting queryOnLineSetting(String serviceName) {
        OnlineSetting setting = OnlineSetting.QueryBuild().serviceName(serviceName)
                .inUse(1).build();
        return onlineSettingMapper.queryOnlineSettingLimit1(setting);
    }
}
